import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
    children: [
      {
        path: '/database/add',
        name: 'database-add',
        component: () => import(/* webpackChunkName: "home" */ '../views/database/Add')
      },
      {
        path: '/database/list',
        name: 'database-list',
        component: () => import(/* webpackChunkName: "home" */ '../views/database/List')
      },
      {
        path: '/database/relative',
        name: 'database-relative',
        component: () => import(/* webpackChunkName: "home" */ '../views/database/Relative')
      },
      {
        path: '/database/init',
        name: 'database-init',
        component: () => import(/* webpackChunkName: "home" */ '../views/database/Init')
      },
      {
        path: '/database/update',
        name: 'database-update',
        component: () => import(/* webpackChunkName: "home" */ '../views/database/Update')
      },
      //  菜单设置
      {
        path: '/menu/list',
        name: 'menu-list',
        component: () => import(/* webpackChunkName: "home" */ '../views/menu/List')
      },
      {
        path: '/menu/add',
        name: 'menu-add',
        component: () => import(/* webpackChunkName: "home" */ '../views/menu/Add')
      },
      //  初始化
      {
        path: '/init/list',
        name: 'menu-list',
        component: () => import(/* webpackChunkName: "home" */ '../views/init/List')
      }
    ]
  },
  {
    path: '/create',
    name: 'create',
    component: () => import(/* webpackChunkName: "home" */ '../views/Create'),
    children: [
      { path: '/project',
        name: 'project',
        component: () => import(/* webpackChunkName: "home" */ '../views/create/Project.vue')
      },
      { path: '/basic',
        name: 'basic',
        component: () => import(/* webpackChunkName: "home" */ '../views/create/Basic.vue')
      },
      { path: '/item',
        name: 'item',
        component: () => import(/* webpackChunkName: "home" */ '../views/create/Item.vue')
      }
    ]
  }
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]
// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
// to 将要访问的路径
// from 代表从哪个路径跳转而来
// next 是一个函数，表示放行
//     next()  放行    next('/login')  强制跳转
//   if (!to.name) {
//     Message({ type: 'error', message: '此页面不存在' })
//     return next('/home')
//   }
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) {
//     Message({
//       type: 'warning',
//       message: '请先登录！！！'
//     })
//     return next('/login')
//   }
//
//   next()
// })
//
// export default router
const router = new VueRouter({
  routes
})

export default router
